<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="taskList">
      <!--      <el-table-column label="流程ID" align="center" prop="id"/>-->
      <el-table-column label="流程名称" align="center" prop="instanceName" />
      <el-table-column label="任务节点名称" align="center" prop="name" />
      <el-table-column label="任务状态" align="center" prop="status" />
      <el-table-column label="办理人" align="center" prop="assignee" />
      <el-table-column label="创建时间" align="center" prop="createdDate" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="examineAndApprove(scope.row)"
            v-hasPermi="['workflow:leave:edit']"
            >审批
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 审批对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      v-if="open"
      width="80%"
      append-to-body
    >
      <el-form
        :model="buyBackReq"
        ref="buyBackReqForm"
        label-width="100px"
        class="demo-dynamic"
        disabled
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="单据编码">
              <el-input :value="buyBackReq.code" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="采购入库单">
              <el-input
                :value="buyBackReq.stockIn.stockInCode"
                placeholder=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="供应商">
              <el-input :value="buyBackReq.supplier.supName" placeholder="" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="业务员">
              <el-input :value="buyBackReq.srcUser.userName" placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="业务部门">
              <el-input :value="buyBackReq.srcDeptName" placeholder="" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单据日期">
              <el-date-picker
                clearable
                :value="buyBackReq.orderDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder=""
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="创建人">
              <el-input :value="buyBackReq.createBy" placeholder="" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="修改人">
              <el-input :value="buyBackReq.modifyBy" placeholder="" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="创建时间">
              <el-date-picker
                clearable
                :value="buyBackReq.createDate"
                type="date"
                value-format="yyyy-MM-dd"
                disabled
                placeholder=""
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="修改时间">
              <el-date-picker
                clearable
                :value="buyBackReq.modifyDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder=""
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="备注">
              <el-input
                type="textarea"
                :value="buyBackReq.remark"
                placeholder=""
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        ref="orderTable"
        :data="buyBackReq.buyBackReqDetailList"
        tooltip-effect="dark"
        style="width: 100%"
        highlight-current-row
      >
        <el-table-column label="序号" width="70" align="left">
          <template slot-scope="scope">
            {{
              scope.$index +
              1 +
              (queryParams.pageNum - 1) * queryParams.pageSize
            }}
          </template>
        </el-table-column>
        <el-table-column prop="goods.proName" label="商品" width="150">
        </el-table-column>
        <el-table-column prop="goods.unitName" label="单位" width="120">
        </el-table-column>
        <el-table-column prop="quantity" label="退货数量" width="120">
        </el-table-column>
      </el-table>
      <el-form
        v-model="approval"
        ref="form"
        label-width="100px"
        class="demo-dynamic"
      >
        <el-form-item label="审批结果">
          <el-radio-group v-model="approval.approvalResult">
            <el-radio :label="2">同意</el-radio>
            <el-radio :label="3">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审批意见">
          <el-input
            type="textarea"
            v-model="approval.approvalOption"
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTask, formDataShow, handleApproval } from "@/api/activiti/task";

export default {
  name: "Leave",
  data() {
    return {
      id: "",
      definitionKey: "",
      businessKey: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假表格数据
      taskList: [],
      buyBackReq: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        processDefinitionKey: "buyBackReqBPMN",
        // processDefinitionKey: "buyBackOrderBPMN",
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        formData: [],
        buyBackReq: { stockInCode: "" },
      },
      approval: {
        approvalResult: 2,
        approvalOption: "",
      },
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询采购退货申请列表 */
    getList() {
      this.loading = true;
      listTask(this.queryParams).then((response) => {
        this.taskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      (this.definitionKey = ""),
        (this.businessKey = ""),
        (this.form = {
          formData: [],
          buyBackReq: { stockInCode: "" },
        });
      this.approval = {
        approvalResult: 2,
        approvalOption: "",
      };
      this.resetForm("form");
    },

    /** 审批按钮操作 */
    examineAndApprove(row) {
      this.reset();
      this.definitionKey = row.definitionKey;
      this.businessKey = row.businessKey;
      this.id = row.id;
      formDataShow(this.id).then((rs) => {
        this.buyBackReq = rs.data;
      });
      this.open = true;
      this.title = "审批采购退货申请单";
    },
    /** 提交按钮 */
    submitForm() {
      this.approval.taskId = this.id;
      handleApproval(this.approval).then((response) => {
        this.$modal.msgSuccess("审批成功");
        this.open = false;
        this.getList();
      });
    },
    /**文档预览**/
    preView(filePath) {
      console.info(filePath);
      if (null == filePath || "" == filePath) {
        this.$alert("申请人没有上传哦", "消息提示", {
          confirmButtonText: "确定",
        });
      } else {
        // let originUrl = 'http://127.0.0.1:80/ruoyi-admin/';   //要预览文件的访问地址'
        window.open(filePath);
      }
      // const bb = originUrl  + aa;
      // window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(bb)));
    },
  },
};
</script>
